<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8"/>
    <title></title>
    {include file='header'}  
</head>

<body>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a>首页</a>
            <a href="{:url('index')}">账户管理</a>
            <a><cite>编辑用户</cite></a>
        </span>
        <div style="float: right;">
            <a class="layui-btn layui-btn-small" href="javascript:location.replace(location.href);" title="刷新">
                <i class="layui-icon layui-icon-refresh-1"></i></a>
        </div>
    </div>
    <div class="x-body">
        <form class="layui-form">            
            <div class="layui-form-item">
                <label class="layui-form-label label-required">登陆名</label>
                <div class="layui-input-block">
                    <input type="text" id="username" name="username" value="{if !empty($data)}{$data.username}{/if}" lay-verify="required" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label label-required">姓名</label>
                <div class="layui-input-block">
                    <input type="text" id="name" name="name" value="{if !empty($data)}{$data.name}{/if}" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">密码</label>
                <div class="layui-input-block">
                    <input type="text" id="login_pwd" name="login_pwd" value="" placeholder="不修改保留空" autocomplete="off" class="layui-input">
                </div>
            </div>
            
            <div class="layui-form-item">
                <label class="layui-form-label">权限</label>
                <div class="layui-input-block">
                    {foreach $authorizes as $authorize}
                    <div style="padding:10px;float:left">
                    <label class="think-checkbox layui-unselect">                   
                    <input type="checkbox"{if !empty($data.role_id)}{if in_array($authorize.id, $data.role_id)} checked{/if}{/if} name="role_id[]" value="{$authorize.id}" lay-ignore> {$authorize.title}                   
                    </label></div>
                {/foreach}
                </div>
            </div>{if $admin.id==1}
            <div class="layui-form-item">
                <label class="layui-form-label">单位</label>
                <div class="layui-input-block">
                    <select id="danwei_id" name="danwei_id" class="layui-select">
                        <option value="">=归属单位=</option>
                        {foreach $danwei as $v}
                    <option value="{$v.id}"{if !empty($data)}{if $data.danwei_id==$v.id} selected=""{/if}{/if}>{$v.name}</option>
                    {/foreach}
                        </select>
                </div>
            </div>{/if}
            <div class="layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="status" value="1"  lay-text="开启|停用"{if !empty($data)}{if $data.status==1} checked=""{/if}{/if} lay-skin="switch">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <div class="layui-input-block">
                <input type="hidden" id="id" name="id" value="{if !empty($data)}{$data.id}{/if}" />
                <button type="button" class="layui-btn btn-fix" lay-filter="save" lay-submit="">保存</button>
                </div>
            </div>
        </form>
    </div>       
<script>
layui.use('form', function(){
  var form = layui.form;  
  //监听提交
  form.on('submit(save)', function(data){
    console.log(data.field)
    //return;
    $.ajax({
        type: "POST",
        url: "{:url('save')}",
        data: data.field,
        datatype: "json",
        success: function (res, textStatus) {        
            console.log(res)                
            if (res.code == 1) {
                layer.msg('操作成功', {icon:1,time:1000 },function(){
                    var index = parent.layer.getFrameIndex(window.name);
                    window.parent.location.reload();
                    parent.layer.close(index);
                });
            }
            else {
                layer.msg(res.msg);
                return false;
            }
        },
        error: function (e) {
            layer.alert('系统出现错误,请检查系统！', { icon: 2 });
            return false;
        }
    });
    return false;
  });
});
</script>
</body>
</html>